<template>
    <div class="index-lists">
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item label="业务人员" prop="servicer">
                    <el-input class="w-[280px]" v-model="queryParams.servicer" />
                </el-form-item>
                <el-form-item label="业务人员部门">
                    <el-input class="w-[280px]" />
                </el-form-item>
                <el-form-item label="合同名称" prop="contractName">
                    <el-input class="w-[280px]" v-model="queryParams.contractName" />
                </el-form-item>
                <el-form-item label="合同编号" prop="contractId">
                    <el-input class="w-[280px]" v-model="queryParams.contractId" />
                </el-form-item>

                <el-form-item label="回款类型" prop="paymentType">
                    <el-select v-model="queryParams.paymentType" class="w-[280px]" clearable>
                        <el-option label="全部" value="1" />
                        <el-option label="正常回款" value="2" />
                        <el-option label="退款" value="3" />
                        <el-option label="订金" value="4" />
                    </el-select>
                </el-form-item>
                <el-form-item label="回款时间" prop="topUrgent">
                    <el-date-picker
                        class="w-[200px]"
                        v-model="queryParams.topUrgent"
                        type="datetime"
                        clearable
                        value-format="YYYY-MM-DD hh:mm:ss"
                        placeholder="请选择回款时间"
                    />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">导出</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
            <!-- <div>
                <el-button v-perms="['answer:add']" type="primary" @click="handleAdd()">
                    <template #icon>
                        <icon name="el-icon-Plus" />
                    </template>
                    新增
                </el-button>
            </div> -->
            <el-table class="mt-4" size="large" v-loading="pager.loading" :data="pager.lists" stripe>
                <el-table-column label="业务人员" prop="servicer" min-width="100" />
                <el-table-column label="合同编号" prop="contractId" min-width="100" />
                <el-table-column label="合同名称" prop="contractName" min-width="100" />
                <el-table-column label="客户名称" prop="customerName" min-width="100" />
                <el-table-column label="案件名称" prop="caseName" min-width="100" />
                <el-table-column label="代理费" prop="agencyFee" min-width="100" />
                <el-table-column label="合同金额" prop="contractValue" min-width="100" />
                <el-table-column label="币别" prop="currency" min-width="100" />
                <el-table-column label="开票币别" prop="paymentCurrency" min-width="100" />
                <el-table-column label="官费" prop="officialFee" min-width="100" />

                <el-table-column label="回款时间" prop="topUrgent" min-width="100" />
                <el-table-column label="计划回款时间" prop="planTopUrgent" min-width="100" />
                <el-table-column label="回款金额" prop="amountCashed" min-width="100" />
                <el-table-column label="回款类型" prop="paymentType" min-width="100" />

                <el-table-column label="开票金额" prop="invoiceAmount" min-width="100" />
                <el-table-column label="开票时间" prop="timeBilling" min-width="100" />
                <el-table-column label="付款方式" prop="paymentMethod" min-width="100" />
                <el-table-column label="备注" prop="remarks" min-width="100" />

                <!-- <el-table-column label="操作" width="120" fixed="right">
                    <template #default="{ row }">
                        <el-button
                            v-perms="['answer:edit']"
                            type="primary"
                            link
                            @click="handleEdit(row)"
                        >
                            编辑
                        </el-button>
                        <el-button
                            v-perms="['answer:del']"
                            type="danger"
                            link
                            @click="handleDelete(row.id)"
                        >
                            删除
                        </el-button>
                    </template>
                </el-table-column> -->
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
        <edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />
    </div>
</template>
<script lang="ts" setup name="answer">
import { answerDelete, answerLists } from '@/api/answer'
import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback'
// import EditPopup from './edit.vue'
// const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false)
const queryParams = reactive({
    topUrgent: '',
    creator: '',
    servicer: '',
    contractId: '',
    contractName: '',
    customerName: '',
    caseName: '',
    agencyFee: '',
    contractValue: '',
    currency: '',
    paymentCurrency: '',
    officialFee: '',
    currencyid: '',
    paymentCurrencyid: '',
    remarks: '',
    topUrgentStart: '',
    topUrgentEnd: '',
    planTopUrgent: '',
    amountCashed: '',
    paymentType: '',
    collectionAgentDate: '',
    collectingAgencyFees: '',
    collectingCompanyAccount: '',
    invoiceAmount: '',
    timeBilling: '',
    paymentMethod: '',
    consolidatedCollection: '',
    invoiceNumber: '',
    payee: '',
    collectingCompanyAccountid: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: answerLists,
    params: queryParams
})

// const handleAdd = async () => {
//     showEdit.value = true
//     await nextTick()
//     editRef.value?.open('add')
// }

// const handleEdit = async (data: any) => {
//     showEdit.value = true
//     await nextTick()
//     editRef.value?.open('edit')
//     editRef.value?.getDetail(data)
// }

const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await answerDelete({ id })
    feedback.msgSuccess('删除成功')
    getLists()
}

getLists()
</script>
